<html>
	<head>

		<script type="text/javascript">
function trasformCase(text,textCase) {
	var endTag;
	if (textCase === "<upcase>") {
		endTag = "</upcase>"
	}
	if (textCase === "<lowcase>") {
		endTag = "</lowcase>"
	}
	if (textCase === "<mixcase>") {
		endTag = "</mixcase>"
	}

	var indexStart = text.indexOf(textCase);

	while (indexStart > -1) {
		var insedeText = text.substring(indexStart + 8, text.indexOf(endTag, indexStart))
		if (textCase === "<upcase>") {
			var insedeText = text.substring(indexStart + 8, text.indexOf(endTag, indexStart));
			var transformedText = insedeText.toUpperCase()
		}
		if (textCase === "<lowcase>") {
			var insedeText = text.substring(indexStart + 8, text.indexOf(endTag, indexStart));
			var transformedText = insedeText.toLowerCase()
		}
		if (textCase === "<mixcase>") {
			var insedeText = text.substring(indexStart + 9, text.indexOf(endTag, indexStart))
			var transformedText = insedeText;
			for (var i = 0; i < transformedText.length; i++) {
				if (Math.floor((Math.random() * 2) + 3) === 3) {
					transformedText = transformedText.replace(transformedText[i], transformedText[i].toUpperCase())
				} else {
					transformedText = transformedText.replace(transformedText[i], transformedText[i].toLowerCase())
				}
			}
		}
		text = text.replace(insedeText, transformedText);
		text = text.replace(textCase, "");
		text = text.replace(endTag, "");
		indexStart = text.indexOf(textCase, indexStart + 1);

	}
	text = text.replace(insedeText, transformedText);
	text = text.replace(textCase, "");
	text = text.replace(endTag, "");
	return text;
}
function doMixCase(text) {
	var indexStart = text.indexOf("<mixcase>");
	while (indexStart > -1) {
		var insedeText = text.substring(indexStart + 9, text.indexOf("</mixcase>", indexStart));
		var mixedText = new String(insedeText);
		for (var i = 0; i < mixedText.length; i++) {
			if (i % 2 == 0) {
				mixedText = mixedText.replace(mixedText[i], mixedText[i].toUpperCase())
			} else {
				mixedText = mixedText.replace(mixedText[i], mixedText[i].toLowerCase())
			}
		}
		text = text.replace(insedeText, mixedText);
		indexStart = text.indexOf("<mixcase>", indexStart + 1);
	}
	return text;
}

function doLowCase(text) {
	var indexStart = text.indexOf("<lowcase>");
	while (indexStart > -1) {
		var insedeText = text.substring(indexStart + 9, text.indexOf("</lowcase>", indexStart));
		var lowerText = insedeText.toLowerCase();
		text = text.replace(insedeText, lowerText);
		indexStart = text.indexOf("<lowcase>", indexStart + 1);
	}
	return text;
}

function onClick() {
	var text = "We are <mixcase>living</mixcase> in a <upcase>yellow submarine</upcase>. We <mixcase>don't</mixcase> have <lowcase>ANYTHING</lowcase> else."
	window.alert(trasformCase(text,"<upcase>"))
	window.alert(trasformCase(text,"<lowcase>"))
	window.alert(trasformCase(text,"<mixcase>"))
	}

		</script>
		<title></title>
	</head>
	<body>
		<pre>
		&quot;We are &lt;mixcase&gt;living&lt;/mixcase&gt; in a &lt;upcase&gt;yellow submarine&lt;/upcase&gt;. We &lt;mixcase&gt;don't&lt;/mixcase&gt; have &lt;lowcase&gt;ANYTHING&lt;/lowcase&gt; else.&quot;
		</pre>
		<button onclick="onClick()" id="buttonOne">Click to see case transformation</button>		
	</body>
</html>